<template>
  <div>
    <el-table :data="tableData" border v-loading="loading" :header-cell-style="{'text-align':'center'}"
              :cell-style="{'text-align':'center'}">
      <el-table-column fixed prop="id" label="编号" width="200"></el-table-column>
      <el-table-column prop="name" label="用户" width="200"></el-table-column>
      <el-table-column prop="pwd" label="密码" width="200"></el-table-column>
      <el-table-column prop="myTime" label="最后修改" width="200" type="date">
      </el-table-column>
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <el-button type="success" icon="el-icon-info" @click="personal()">详情</el-button>
          <el-button type="primary" icon="el-icon-edit" @click="edit(scope.row)">修改</el-button>
          <el-popconfirm title="确认删除吗?" @confirm="delUser(scope.row)">
            <el-button slot="reference" type="warning" icon="el-icon-delete">删除
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination background layout="prev, pager, next"
                   :total="total" page-size="6" @current-change="page"
                   style="margin:20px;">
    </el-pagination>
  </div>
</template>

<script>
  const axios = require('axios')
  export default {
    methods: {
      delUser(row) {
        /* alert('删除按钮'+row.id)*/
        const _this = this
        axios.delete('http://localhost:9000/user/delById/' + row.id).then(function (resp) {
          _this.$alert('用户<' + row.name + '>已删除', '消息', {
            confirmButtonText: '确定',
            callback: action => {
              window.location.reload()
            }
          });
        })
      },
      edit(row) {
        this.$router.push({
          path: '/myUpdate/update',
          query: {
            id: row.id
          }
        });
        console.log('要更新的id是：' + row.id)
      },
      page(currentPage) {
        //alert(currentPage)  输出分页的信息 测试
        const _this = this
        this.$axios.get('http://localhost:9000/user/findPage/' + currentPage + '/6').then(function (resp) {
          //console.log(resp)
          _this.tableData = resp.data.content
          _this.pageSize = resp.data.size
          _this.total = resp.data.totalElements
        })
      },
      personal() {
        this.$router.push('/user/personal')
      }
    }, created() {
      const _this = this
      this.$axios.get('http://localhost:9000/user/findPage/1/6').then(function (resp) {
        //console.log(resp)
        _this.tableData = resp.data.content
        _this.pageSize = resp.data.size
        _this.total = resp.data.totalElements
      })
    },
    data() {
      return {
        pageSize: '1',
        total: null,
        tableData: null,
        loading: false
      }
    }
  }
</script>

<style>
  .el-button {
    font-size: smaller;
  }

  .el-button--warning {
    background: red;
  }
</style>
